<template>
  <div class="guide" :style="{ height: guideHeight }">
    <template v-if="isExpanded">
      <div v-for="(item, index) in data" class="item" :key="index" @click="item.operate">
        <div class="icon">
          <img :src="item.icon" />
        </div>
        <div class="text">{{ item.text }}</div>
      </div>
    </template>

    <div class="operate" @click="toggleExpand">
      <a-icon v-if="!isExpanded" type="left" />
      <span>{{ isExpanded ? '收起' : '展开' }}</span>
      <a-icon v-if="isExpanded" type="right" />
    </div>
  </div>
</template>

<script>
export default {
  props: {
    data: Array
  },
  data() {
    return {
      isExpanded: true
    }
  },
  computed: {
    guideHeight() {
      return this.isExpanded ? this.data.length * (98) + 54 + 'px' : '54px'
    }
  },
  methods: {
    toggleExpand() {
      this.isExpanded = !this.isExpanded
    }
  }
}
</script>

<style lang="less" scoped>
.guide {
  border-radius: 16px 0px 0px 16px;
  background: #165dff;
  width: 88px;
  overflow: hidden; /* 隐藏超出的部分 */
  transition: height 0.1s ease-in-out;
  .item {
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 4px;
    padding: 16px;
    cursor: pointer;

    .icon {
      width: 40px;
      height: 40px;
      img {
        width: 100%;
        height: 100%;
      }
    }

    .text {
      color: #fff;
      font-size: 14px;
      line-height: 22px;
    }
  }

  .operate {
    padding: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2px;
    color: #bedaff;
    font-size: 14px;
    line-height: 22px;
    cursor: pointer;
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE/Edge */
    user-select: none;
  }
}
</style>
